% File: sc_fde_ib_snr_evolution.m
% -------------------------------
% This script simulates output SNR vs. input variance of iterative
% equalizer.

H_tmp  = squeeze(H).';
H_tmp  = reshape(H_tmp,[],nt);

H_tmp_pow = abs(H_tmp).^2;

% eb_n0     = 4; % Eb/N0 in dB
% snr_in    = eb_n0 + 10*log10(Cr*log2(M_mod)) - 10*log10(sf); % convert Eb/N0 into SNR
% 
% npow_dB   = xtxPower_mean_dB-snr_in;    % compute noise power
% npow      = 10^(npow_dB/10);            % convert backto linear scale
% npow_norm = npow/xtxPower_mean;         % noise power normalized to tx power

% snr_in    = SNR(n);
npow_norm = noisePow_norm;

% var_tmp   = 1e-8*(1: 1e4: 1e8);  % normalized var.
mu_tmp    = zeros(size(var_tmp));
h_snrevo_waitbar = waitbar(0,'Please wait...');
for n_var = 1: length(var_tmp)
    mu_tmp(n_var) = mean(H_tmp_pow./(var_tmp(n_var).*H_tmp_pow+npow_norm));
    waitbar(n_var/length(var_tmp))
end
close(h_snrevo_waitbar)
mse_tmp   = (1./mu_tmp - var_tmp); % normalized mse.
sinr_tmp  = 1./mse_tmp;

% figure();
% semilogx(var_tmp, sinr_tmp);
% set(gca,'XDir','reverse')
% xlabel('Average Variance'); ylabel('SNR');
% grid on
% legend('Transfer Function of Equalizer', 'Location', 'SouthEast');
% title('SNR Evolution Chart');
% 
% figure();
% semilogx(var_tmp, mse_tmp);
% set(gca,'XDir','reverse')
% xlabel('Average Variance'); ylabel('MSE');
% grid on
% legend('Transfer Function of Equalizer', 'Location', 'NorthEast');
% title('MSE Evolution Chart');

% filename = 'sc_fde_ib_snr_evolution.mat';
% save(filename, 'eb_n0', 'snr_in', 'var_tmp', 'SER_per', 'sinr_tmp');

% z = x; % dummy rx

% End of script.